package com.macllvm.whale.sound;

import android.media.AudioManager;
import android.media.SoundPool;
import android.content.Context;
import android.util.Log;


import java.lang.Integer;
import java.util.HashMap;
import com.macllvm.whale.R;

public class SoundPlayer {
    private Context mContext;
    private SoundPool mSoundPlayer;
    private AudioManager mAudioManager;
    private HashMap<Integer, Integer> mSoundRes;

    public SoundPlayer(Context context){
        mContext = context;
        mSoundRes = new HashMap<Integer, Integer>();
        mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
        mSoundPlayer = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
        mSoundRes.put(1, mSoundPlayer.load(context, R.raw.newmsg, 1));
    }

    public void playNewMsg() {
        float audioMaxVolumn = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        float volumnCurrent = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        float volumnRatio = volumnCurrent / audioMaxVolumn;
        mSoundPlayer.play(mSoundRes.get(1), volumnRatio, volumnRatio, 1, 0,  1f);
    }
}